package hhf.flex.soundapi.core {

	public class InterpolationType {
		protected var name:String;
		public var nbsample:int;
		protected static var localInstantiation:Boolean = false;

		public function InterpolationType(name:String, nbsample:int) {
			if(!localInstantiation) throw Error("Private constructor");
			this.name = name;
			this.nbsample = nbsample;
		}

		
		private static var _SAMPLE:InterpolationType; 
		public static function get SAMPLE():InterpolationType {
			if(!_SAMPLE) { 
				localInstantiation = true; 
				_SAMPLE = new InterpolationType("SAMPLE", 1);
				localInstantiation = false;
			}
			return _SAMPLE;
		} 
		private static var _LINEAR:InterpolationType; 
		public static function get LINEAR():InterpolationType {
			if(!_LINEAR) { 
				localInstantiation = true; 
				_LINEAR = new InterpolationType("LINEAR", 1);
				localInstantiation = false;
			}
			return _LINEAR;
		} 
		private static var _POLYNOMIAL:InterpolationType; 
		public static function get POLYNOMIAL():InterpolationType {
			if(!_POLYNOMIAL) { 
				localInstantiation = true; 
				_POLYNOMIAL = new InterpolationType("POLYNOMIAL", 3);
				localInstantiation = false;
			}
			return _POLYNOMIAL;
		} 
		
		public static function valueOf(name:String):InterpolationType {
			for each(var val:InterpolationType in values()) {
				if(val.name.toUpperCase() == name.toUpperCase()) return val;
			}
			return null;
		}
		
		public static function values():Array {
			return [SAMPLE, LINEAR, POLYNOMIAL];
		}
		
		public function toString():String {
			return this.name;
		}
		
		public function equals(obj:Object):Boolean {
			if(!obj) return false;
			return this.name == obj.name;
		}
	}
}